#!/usr/bin/env python3

s = [3, 5, 7, 8]
c = 0
numSum = sum(s)

for i in s:
    for j in s:
        if i == j:
            continue
        for k in s:
            if i == k or j == k:
                continue
            n = i * 1000 + j * 100 + k * 10 + (numSum - i - j - k)
            if n % 5 != 0:
                print("%d " % (n), end="")
                c += 1

print("\n c = %d" % (c))

c = 0
for n in range(3578, 8754):
    i = n % 10
    j = n // 10 % 10
    k = n // 100 % 10
    l = n // 1000

    if i in s and j in s and k in s and l in s      \
         and i != j and i != k and i != l           \
         and j != k and j != l and k != l           \
         and n % 5 != 0:
        print("%d " % (n), end="")
        c += 1

print("\n c = %d" % (c))

